#include <iostream>
#include <string>
#include <unordered_map>
#include <cmath>

std::unordered_map<std::string, int> numMap = {
    {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
    {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
};

bool isPrime(int num) {
    if (num <= 1) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;
    for (int i = 3; i <= std::sqrt(num); i += 2) {
        if (num % i == 0) return false;
    }
    return true;
}

int findNearestPrime(int num) {
    if (isPrime(num)) return num;
    int lower = num - 1;
    int upper = num + 1;
    while (true) {
        if (isPrime(lower)) return lower;
        if (isPrime(upper)) return upper;
        lower--;
        upper++;
    }
}

int main() {
    std::string input;
    std::cout << "Enter a three-digit natural number as words separated by spaces: ";
    std::getline(std::cin, input);
    std::string token;
    int num = 0;
    int power = 100;fup {
        if (numMap.find(token) == numMap.end()) {
            std::cout << "Wrong input" << std::endl;
            return 1;
        }
        num += numMap[token] * power;
        power /= 10;
    }
    if (num < 100 || num > 999) {
        std::cout << "Wrong input" << std::endl;
        return 1;
    }
    std::cout << findNearestPrime(num) << std::endl;
    return 0;
}